package ch.gibb.learnit.client.controllers;

import org.apache.log4j.Logger;

import java.io.IOException;

/**
 * Controller for the logout
 *
 * @author Bernard Jaquet
 * @version 1.0
 */
public class LogoutAction extends MasterAction {
    private final Logger masterLogger = Logger.getLogger(LogoutAction.class);

    @Override
    public int openPage() {

        // Logs out user
        logoutUser();
        try {

            // Redirects user to the login
            return redirect("");
        } catch (IOException e) {
            getErrors().addMessage("Es ist ein unbekannter Fehler aufgetreten.");
            masterLogger.error("Error while logout " + e.getMessage(), e);
            return 500;
        }
    }
}
